<template>
    <div>
        <i-table  border :columns="columns" :data="dataList">
            <template slot-scope="{ row }" slot="action">
                <div class="action-button">
                    <Button v-if="row.dept_audit_status==='draft'" type="primary" size="small" style="margin-right: 5px" @click="toEdit(row.id)">编辑</Button>
                    <Button v-if="row.dept_audit_status==='draft'" type="error" size="small" style="margin-right: 5px" @click="openModal(row.id)">删除</Button>
                    <Button type="success" size="small" @click="toDetail(row.id)">详情</Button>
                </div>
            </template>
        </i-table>
        <Page :total="pageInfo.total" :current="pageInfo.pageNo" @on-change="changePage"></Page>
        <Modal
                v-model="modal"
                title="确认操作"
                width="20"
                @on-ok="deleteForm">
            <div style="text-align:center">
                <p>是否确认删除!</p>
            </div>
        </Modal>
    </div>
</template>+

<script>
import { findPageList, deleteForm } from '@/api/outbreak-management/city-operation/environmental-improvement/waste-mask-collection'
// 环境整治--废弃口罩收集
export default {
  data () {
    return {
      modal: false,
      id: '',
      columns: [
        {
          title: '上报日期',
          minWidth: 120,
          key: 'imp_date',
          render: (h, params) => {
            let date = this.$common.moment(params.row.imp_date).format('YYYY-MM-DD')
            return h('div', date)
          }
        },
        {
          title: '公安',
          minWidth: 120,
          key: 'ga'
        },
        {
          title: '环卫',
          minWidth: 120,
          key: 'hw'
        },
        {
          title: '农村',
          minWidth: 120,
          key: 'nc'
        },
        {
          title: '公共',
          minWidth: 120,
          key: 'gg'
        },
        {
          title: '其他',
          minWidth: 120,
          key: 'qt'
        },
        {
          title: '审核状态',
          minWidth: 120,
          key: 'dept_audit_status',
          render: (h, params) => {
            let date = '未知状态'
            let dept_audit_status = params.row.dept_audit_status
            let leader_audit_status = params.row.leader_audit_status
            if (dept_audit_status === 'draft') {
              date = '未提报'
            } else if (dept_audit_status === 'commit') {
              date = '部门已审核'
            } else if (dept_audit_status === 'audited' && leader_audit_status === 'unaudited') {
              date = '分项已审核'
            } else if (dept_audit_status === 'audited' && leader_audit_status === 'audited') {
              date = '区已审核'
            }
            return h('div', date)
          }
        },
        {
          title: '操作',
          slot: 'action',
          fixed: 'right',
          minWidth: 180,
          align: 'center'
        }
      ],
      dataList: [ ],
      pageInfo: {
        flag: 1,
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  methods: {
    toDetail (id) {
      this.$router.push({ name: 'waste-mask-collection-add', query: { id: id, showDetail: true } })
    },
    toEdit (id) {
      this.$router.push({ name: 'waste-mask-collection-add', query: { id: id } })
    },
    changePage (index) {
      this.pageInfo.pageNo = index
      this.getTableData()
    },
    getTableData () {
      findPageList(this.pageInfo).then(({ data }) => {
        let { data: res } = data
        this.dataList = res.results
        this.pageInfo.total = res.totalRecord
      })
    },
    // 打开弹窗
    openModal (id) {
      if (id) {
        this.modal = true
        this.id = id
      }
    },
    // 删除数据
    deleteForm () {
      deleteForm({ id: this.id }).then(({ data }) => {
        let { errcode } = data
        if (errcode === 0) {
          this.$Message.success('删除成功!')
          // 清空数据
          this.id = ''
          this.getTableData()
        } else {
          this.$Message.warning('删除失败!')
        }
      })
    }
  },
  created () {
    this.getTableData()
  }
}

</script>

<style scoped>

</style>

<style>
    .submit-button{
        display: flex;
        justify-content: flex-end;
        margin: 10px 0 ;
    }
</style>
